USOCK_OBJ = usocket.o userver.o uclient.o umessage.o
USOCK_LIBNAME = libusock
USOCK_DST_PATH = ../../rootfs/usr/lib

USOCK_SO_LDFLAG=-Wl,-soname=$(USOCK_LIBNAME).so
INCLUDE= -I../libxml2/include -I../include -I../xml_parser -I../cjson
LDFLAGS= -L../libxml2/.libs -lxml2 -lpthread -L../cjson -lcjson -L../xml_parser -lxmlparser
INSTALL ?= cp -a
CROSS_COMPLIE = /opt/dspg/v1.3.4-rc4/sysroots/x86_64-dspg-linux/usr/bin/armv5te-dspg-linux-uclibceabi/arm-dspg-linux-uclibceabi-
CC = $(CROSS_COMPLIE)gcc
AR = $(CROSS_COMPLIE)ar
PIC_FLAGS = -fPIC
CFLAGS = $(PIC_FLAGS) -Wall -Werror

#library file extensions
SHARED = so
STATIC = a

#library names
USOCK_SHARED = $(USOCK_LIBNAME).$(SHARED)
USOCK_STATIC = $(USOCK_LIBNAME).$(STATIC)

SHARED_CMD = $(CC) -shared -o

.PHONY: all shared static

all: shared static

shared: $(USOCK_SHARED)

static: $(USOCK_STATIC)


#static libraries
$(USOCK_STATIC): $(USOCK_OBJ)
	$(AR) rcs $@ $^

#shared libraries
$(USOCK_SHARED): $(USOCK_OBJ)
	$(SHARED_CMD) $@ $^ $(XMLP_SO_LDFLAG) $(LDFLAGS)

#objects
%.o: %.c
	$(CC) $(INCLUDE) $(CFLAGS) -s -c $^ -o $@ $(LDFLAGS)

install: 
	$(INSTALL) $(USOCK_SHARED) $(USOCK_DST_PATH)

clean:
	$(RM) $(USOCK_OBJ) $(USOCK_SHARED) $(USOCK_STATIC)
